#!/usr/bin/perl
#
#	scan.pl
#
#	Scott Lawrence
#	2005-02-18
#
#	scans directories of amiga fonts, to generate BDF fonts
#
#

$conv	= "/Users/sdl/src/yorgle/amiwm/fonts/ami2bdf";

$amigafontdir = "/Users/sdl/src/yorgle/extras/fonts/Amiga/";

# from this directory, we have a few subdirs:
#	Commodore, Jerry, UmlautLlama  		(foundry)
# from there, we have things like:
#	garnet/
#	garnet.font
# .font files are ignored
# directories are scanned for fonts:
#	8
#	9
# these are the sizes of the fonts contained therein
#	8c	colorfont (skipped)
#	9e	extended (parsed?)

opendir FOUNDRY, "$amigafontdir";

foreach $foundry( readdir FOUNDRY )
{
    next if( "." eq substr $foundry, 0, 1 );
    next if( "CVS" eq $foundry );
    #printf "Foundry: $foundry\n";

    $fontdir = $amigafontdir . $foundry . "/";
    opendir FONTNAME, "$fontdir";
    foreach $fontname( readdir FONTNAME )
    {
	next if( "." eq substr $fontname, 0, 1 );
	next if( "CVS" eq $fontname );

	$ifontdir = $fontdir . $fontname;
	next if( !-d $ifontdir );

	#printf " %12s %20s ", $foundry, $fontname; 

	opendir SIZES, "$ifontdir";
	foreach $size( readdir SIZES )
	{
	    next if( "." eq substr $size, 0, 1 );
	    next if( "CVS" eq $size );

	    # determine rough font type
	    $extendedfont = 0;
	    $colorfont = 0;

	    if( -1 != index lc $size, "e" ) { $extendedfont = 1; }
	    if( -1 != index lc $size, "c" ) { $colorfont = 1; }

	    $realsize = $size;
	    $realsize =~ s/[ceCE]//g;

	    if( 1 == $colorfont )
	    {
#		printf " [$realsize u]";
	    } elsif( 1 == $extendedfont ) {
#		printf " [$realsize e]";
	    } else {
#		printf " $realsize";
	    }

	    if( $colorfont == 0 )
	    {
		if( $foundry eq "Jerry" ){ $foundry = "UmlautLlama"; }

		# original
		printf "%15s %10s %s\n", $foundry, $fontname, $size;
		$ocmd = sprintf "%s %s/%s %s %s %s_%s_%s.bdf\n",
			$conv,
			$ifontdir, $size,
			$foundry, $fontname,
			$foundry, $fontname, $size;
		`$ocmd`;

		# scanlines
		$cmd = $ocmd;
		$cmd =~s/\.bdf/_scn.bdf -s/g;
		`$cmd`;

		# doublesize
		$cmd = $ocmd;
		$cmd =~s/\.bdf/_dbl.bdf -d/g;
		`$cmd`;
		
		#### additional height modes
		$cmd = $ocmd;
		$cmd =~s/\.bdf/+1.bdf -h/g;
		`$cmd`;

		# scanlines
		$cmd = $ocmd;
		$cmd =~s/\.bdf/_scn+1.bdf -sh/g;
		`$cmd`;

		# doublesize
		$cmd = $ocmd;
		$cmd =~s/\.bdf/_dbl+1.bdf -dh/g;
		`$cmd`;
		

	    }

	}
	closedir SIZES;

#	printf "\n";

    }
    closedir FONTNAME;


}
closedir FOUNDRY;


